#!/bin/bash

#+--------------------------------------------------------------------------------------------
#|Description:  This shell script used download and cross compile open source libs
#|     Author:  GuoWenxue <guowenxue@gmail.com>
#|  ChangeLog:
#|           1, Initialize 1.0.0 on 2011.04.12
#+--------------------------------------------------------------------------------------------

source ../script_env.sh

function compile_libevent()
{
	VERSION=2.1.12-stable
    SRC_NAME=libevent-${VERSION}
    if [ -f ${PREFIX_PATH}/lib/libevent.a ] ; then
        pr_warn "$SRC_NAME already compile and installed"
        return 0;
    fi

    pr_info "Start compile $SRC_NAME "

    if [ ! -d $SRC_NAME ] ; then
	   if [ ! -f ${SRC_NAME}.tar.gz ] ; then
	   	  wget https://github.com/libevent/libevent/releases/download/release-${VERSION}/${SRC_NAME}.tar.gz
	   fi

	   tar -xzf ${SRC_NAME}.tar.gz
    fi

    cd ${SRC_NAME}

	set -x
	./configure ${CONFIG_CROSS} --prefix=${PREFIX_PATH} --disable-openssl --disable-malloc-replacement --disable-samples
    make && make install

    cd -
}

compile_libevent

